/**
 * Create by richliu1023
 * @date 2016-06-28
 * @email richliu1023@gmail.com
 * @github https://github.com/RichLiu1023
 * @description a simple explanation
 */
class FPSCounter {
	private _fps = 0;
	private _tempCount = 0;
	private _calcCounter = 0;
	private _recordDateList = new Array();

	public static MAX_COUNT = 60;

	public constructor() {
	}

	update = function () {
		this._tempNow = new Date();
		this._recordDateList.push( this._tempNow );
		//统计fps
		this._calcCounter++;
		if ( this._calcCounter > 20 ) {
			this._calcCounter = 0;
			//移除超过总数量上限的date
			while ( this._recordDateList.length > FPSCounter.MAX_COUNT ) {
				this._recordDateList.shift();
			}
			this._tempCount = this._recordDateList.length;
			this._tempStart = this._recordDateList[ 0 ];
			this.fps = (this._tempNow.getTime() - this._tempStart.getTime()) / 1000;
			this.fps = Math.floor( this._tempCount / this.fps );
		}
	}
}